<?php
class log_message_1 extends Update_Model_Database_AbstractChange{

	protected $comment="Создание таблицы log_message";

	public function up(){
		$sql="CREATE TABLE `log_message` (
		  `id` int(11) NOT NULL AUTO_INCREMENT,
		  `message` text,
		  `username` char(20) DEFAULT NULL,
		  `resource` char(30) DEFAULT NULL,
		  `timestamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
		  `priorityName` char(20) DEFAULT NULL,
		  `priority` int(11) DEFAULT NULL,
		  `addition` text,
		  PRIMARY KEY (`id`,`timestamp`)
		) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT
		";
		$this->db->query($sql);
		$sql="
		ALTER TABLE `log_message` PARTITION BY RANGE (YEAR(`timestamp`)) (
			PARTITION p13 VALUES LESS THAN (2013),
			PARTITION p14 VALUES LESS THAN (2014),
			PARTITION p15 VALUES LESS THAN (2015),
			PARTITION p16 VALUES LESS THAN (2016),
			PARTITION p17 VALUES LESS THAN (2017),
			PARTITION p18 VALUES LESS THAN (2018),
			PARTITION p19 VALUES LESS THAN (2019),
			PARTITION p20 VALUES LESS THAN (2020)
		)
		";
		$this->db->query($sql);
	}

	public function down(){
		$sql='DROP TABLE IF EXISTS log_message;';
		$this->db->query($sql);
	}

}